<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_generalcourse extends Controller_Abstract {
	//科目 
	function actionIndex(){
		$append = array("acct_id"=>$_SESSION['acct']['id']);
		$this->union_table = papergeneralcourse::meta();
		$this->lists($append);
		if($this->_context->subject_id){
			$this->_view['subject_id'] = $this->_context->subject_id;
		}
	}
	function actionAdd(){
		if($this->_context->isGET()){
	    	if(!empty($this->_context->id)){
	    		$course = papergeneralcourse::find('id=?',$this->_context->id)->getOne();
	    		$this->_view['course'] = $course;
	    	}
	    	if($this->_context->subject_id){
				$this->_view['subject_id']=$this->_context->subject_id;
			}
	    }
		if($this->_context->isPOST()){
			if(!empty($this->_context->id)){
				$course = papergeneralcourse::find('id=?',$this->_context->id)->getOne();
				$course->name=trim($this->_context->name);
				$course->weight = intval($this->_context->weight);
				if (!empty($this->_context->viplevel)) {
					$viplevel = $this->_context->viplevel;
					if(in_array(0, $viplevel)){
						$course->viplevel=0;
					}else{
						$course->viplevel=implode(',',$viplevel);
					}
				}
		        $course->save(0,'update');
			}else{
				$course = new papergeneralcourse;
				$course->name=trim($this->_context->name);
				$course->subject_id=intval($this->_context->subject_id);

				$course->weight = intval($this->_context->weight);
				$course->acct_id = $_SESSION['acct']['id'];
				if (!empty($this->_context->viplevel)) {
					$viplevel = $this->_context->viplevel;
					if(in_array(0, $viplevel)){
						$course->viplevel=0;
					}else{
						$course->viplevel=implode(',',$viplevel);
					}
				}
				$course->save(0,'create');
			}

			if(!$_POST['id'])	{
	            Syslog::logs ( '添加课程,id :' . $course->id );
	        }else{
	        	
		        Syslog::logs ( '编辑课程,id :' . $course->id );
		    }
	        $this->_context->forwardUrl = url("generalcourse").'/index/subject_id/'.$course->subject_id;
			$this->success('编辑成功');
		}
	}
	function actionDelSubject(){
		Syslog::logs("删除综合试卷，ID：".print_r($this->_context->ids,true));
	     $this->union_table = papergeneralcourse::meta();
	     $this->delete(array('id'=>$this->_context->ids));
	}
}